package com.neu.controller;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neu.pojo.ResultJson;
import com.neu.pojo.User;
import com.neu.service.UserService;

@RestController
@RequestMapping("/login")
public class LoginController {
	// 代码编写处
	@Autowired
	private UserService userService;

	@PostMapping
	public ResultJson login(@RequestBody User user) {
		if (StringUtils.isAnyEmpty(user.getUserName(), user.getPassword())) {
			return new ResultJson(500, "登录失败，账户或者密码不能为空");
		}
		User _user = userService.checkUserExists(user);
		if (_user != null) {
			// 登录成功
			return new ResultJson(_user.getUserName() + _user.getPassword());
		}
		return new ResultJson(500, "登录失败！");
	}
}
